package com.garagesale.data;
// Generated May 3, 2011 8:59:20 PM by Hibernate Tools 3.2.1.GA


import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * ShoppingCart generated by hbm2java
 */
@Entity
@Table(name="shopping_cart"
    ,catalog="garage_sale"
)
public class ShoppingCart  implements java.io.Serializable {


     private Integer shoppingCartId;
     private User user;
     private String sessionId;
     private Date created;
     private Date updated;
     private Set<Item> items = new HashSet<Item>(0);

    public ShoppingCart() {
    }

    public ShoppingCart(User user, String sessionId, Date created, Date updated, Set<Item> items) {
       this.user = user;
       this.sessionId = sessionId;
       this.created = created;
       this.updated = updated;
       this.items = items;
    }
   
     @Id @GeneratedValue(strategy=IDENTITY)
    
    @Column(name="shopping_cart_id", unique=true, nullable=false)
    public Integer getShoppingCartId() {
        return this.shoppingCartId;
    }
    
    public void setShoppingCartId(Integer shoppingCartId) {
        this.shoppingCartId = shoppingCartId;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="user_id")
    public User getUser() {
        return this.user;
    }
    
    public void setUser(User user) {
        this.user = user;
    }
    
    @Column(name="session_id", length=256)
    public String getSessionId() {
        return this.sessionId;
    }
    
    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="created", length=0)
    public Date getCreated() {
        return this.created;
    }
    
    public void setCreated(Date created) {
        this.created = created;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="updated", length=0)
    public Date getUpdated() {
        return this.updated;
    }
    
    public void setUpdated(Date updated) {
        this.updated = updated;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="shoppingCart")
    public Set<Item> getItems() {
        return this.items;
    }
    
    public void setItems(Set<Item> items) {
        this.items = items;
    }

    public int getCartSize()
    {
        return null == items ? 0 : items.size();
    }


}


